/*
** Global memory allocator wrapper for LuaJIT.
** Replaces system malloc/free with global shared allocator using symbol interception.
*/

#ifndef _LJ_GLOBAL_ALLOC_H
#define _LJ_GLOBAL_ALLOC_H

#include "lj_def.h"
#include "lj_state.h"

/* Enable global allocator replacement */
#ifndef LUAJIT_USE_SYSMALLOC
#define LJ_GLOBAL_ALLOC_ENABLED
#endif

/* Forward declarations for global allocator functions */
LJ_FUNC void *get_global_shared_allocator(void);
LJ_FUNC void *lj_alloc_f_threadsafe(void *msp, void *ptr, size_t osize, size_t nsize);

/* System malloc/free function pointers (for fallback) - declared as static in .c file */

/* Global allocator wrapper functions */
LJ_FUNC void *lj_global_malloc(size_t size);
LJ_FUNC void lj_global_free(void *ptr);
LJ_FUNC void *lj_global_realloc(void *ptr, size_t size);
LJ_FUNC void *lj_global_calloc(size_t nmemb, size_t size);

/* Initialization function */
LJ_FUNC void lj_global_alloc_init(void);

#endif
